<template>
	<view>
		<uv-navbar :title="title" :placeholder="true" :autoBack="true"></uv-navbar>
		
		<!-- <block v-if="chackAuth==1"> -->
		<view class="modelBox">
			<view class="flex" >
				<image  class="w-40 h-40" src="../../static/icon/ic2.png" mode=""></image>
				<view class="font-32 font-weight m-l-10">真人认证(身份证)</view>
			</view>
			<view class="font-24 grey m-t-20">认证后获得系统优先推荐和认证标识</view>
			<view class="scBox" @click="addImage">
				<image class="textC w-200 h-200" :src="$util.img(ImageUrl)" mode=""></image>
				<image src="/static/rz.png" mode="" class="textC w-200 h-200"></image>
			</view>
			<button class="authentication" @click="renZheng">去认证</button>
		</view>
		<!-- </block> -->
		<view class="" style="padding: 20rpx;">
			<view class="modelBox" v-html="obj.content"></view>
		</view>
	</view>
</template>

<script>
	import htmlTxt from "@/otherpages/protocol/protocol"
	import base from "@/common/js/config.js"
	export default {
		data() {
			return {
				ImageUrl:'',
				chackAuth:0,
				obj:{},
				title:'用户协议'
			};
		},
		onShow() {
			this.isAuth()
			this.getProtocol()
		},
		mixins: ['base'],
		methods:{
			getProtocol() {
				this.$api.sendRequest({
					url:'/api/Index/article',
					data:{
						type:'用户协议'
					},success:res=>{
						this.obj = res.data
					}
				})
			},
			isAuth() {
				this.$api.sendRequest({
					url:'/api/Index/chack_auth',
					data:{},
					
					success:res=>{
					
						this.chackAuth = res.data
						if(res.data==1) {
							this.title = '认证中心'
						}
					}
				})
			},
			renZheng() {
				if(!this.ImageUrl) {
					uni.showToast({
						title:'请上传图片',
						icon:'error'
					})
					return
				}
				this.$api.sendRequest({
					url:'/api/user/getsgin',
					data:{
						ImageUrl:this.ImageUrl
					},success:res=>{
						if(res.code==1) {
							uni.showToast({
								title:'上传成功',
								icon:'none'
							})
						}else {
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
						}
					}
				})
			},
			// 添加图片
			addImage() {
				uni.chooseImage({
					count: 1,
					success: res => {
						res.tempFilePaths.forEach((item, i) => {
							wx.showLoading({
								title: '上传中(' + (i + 1) + '/' +
									res.tempFilePaths.length + ')'
							})
							uni.uploadFile({
								url: `${base.baseUrl}api/Common/upload`,
								filePath: item,
								name: 'file',
								success: resA => {
									let a = JSON.parse(resA.data)
									this.ImageUrl = a.data.fullurl
								},
								fail: errA => {
									console.log(errA);
								}
							});
							if (i + 1 == res.tempFilePaths.length) {
								wx.hideLoading()
							}
						})
			
					},
					fail(err) {
						console.log(err);
					}
				})
			
			},
		}
	}
</script>

<style lang="scss">
	.scBox {
		padding: 80rpx 247rpx;
	}
	.authentication {
		width: 630rpx;
		height: 80rpx;
		line-height: 80rpx;
		background: #04cbff;
		border-radius: 10rpx;
		margin: 0 auto;
	}
</style>
